package com.hospital.vac.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hospital.vac.controller.dto.UserAddressDto;
import com.hospital.vac.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @description 用户数据访问层
 * @return
 * @author ANLGIN
 * @since 2023/3/9 17:07
 */

public interface UserMapper extends BaseMapper<User> {
    /**
    * 分页查询用户信息
    */
    Page<User> findPage(Page<User> page, @Param("nickName") String nickName);

    /**
    * 查询地址数量
    */
    @Select("select count(id) count, address from user GROUP BY address")
    List<UserAddressDto> countAddress();

    /**
    * 根据用户名查询用户密码
    */
    @Select("select password from user where username=#{username}")
    User selectByName(String username);

    /**
    * 修改用户密码
    */
    @Update("update user set password = #{newPass} where id = #{userId}")
    int updatePass(Map<String, Object> map);
}
